<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <my-test ref="mytest"></my-test>
        <button @click="getMyTest">获取my-test组件中的值</button>
        <button @click="getRoot">获取 $root 组件中的值</button>
    </div>
</body>
<script src="https://cn.vuejs.org/js/vue.js"></script>
<script>
    Vue.component("my-test",{
        template:`
            <h1>
                my-test
                {{this.$root.msg}}    
            </h1>
        `
    });
    let vm = new Vue({
        el : "#app",
        data : {
            msg:"😀",
        },
        methods:{
            getMyTest:function(){
                console.log(this.$refs.mytest);
            },
            getRoot:function(){ 
                console.log(this.$root.msg);
            }
        }





    });
</script>
</html>